<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>register</title>
</head>
<body>
<div>
    <form>
        <div>
            <lable>登录名</lable>
            <input type="text" id="loginname">
        </div>
        <div>
            <label>密码:</label>
            <input type="password" id="pwd">
        </div>
        <div>
            <label>性别</label>
            <input type="radio" name="sex" id="nan" value="男" checked>男
            <input type="radio" name="sex" id="nv" value="女" >女
        </div>
        <div>
            <button type="button" id="reg">注册</button>
            <button type="reset" id="reset">重置</button>
        </div>
    </form>
</div>
<script type="text/javascript">
    function $(id) {
        return document.getElementById(id);
    }

    $("reg").onclick = function () {
        let name = $("loginname").value;
        let pwd = $("pwd").value;
        let sex = "男";
        if ($("nv").checked) {
            sex = "女";
        }
        // localStorage.setItem("loginname",name);
        let user={"loginname":name,"pwd":pwd,"sex":sex};
        let str = JSON.stringify(user);
        localStorage.setItem(name,str);
        alert("注册成功");
        location.href="msg.html";
    };
</script>

</body>
</html>